<?php
/*
	收入明细
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>intval($_RQ['status']));
	if($_SESSION['storeids']){
		$params['storeid']=$_SESSION['storeids'];
	}else{
		if($_SESSION['role_id']!=14 && !$_SESSION['role_id']==15 && !$_SESSION['role_id']==17){
			$params['storeid']=$_SESSION['storeid'];
		}
	}
	$return['params']['status']=intval($_RQ['status']);
	if($_RQ['status']==6){
		$params['status']=0;
		$tstart= mktime(0,0,0,date('m'),date('d'),date('Y'));
		$tend =$tstart+24*3600;
		$params['timenum <']=$tend;
	}
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['memberid']){
		$params['memberid']=intval($_RQ['memberid']);
		$return['params']['memberid']=$_RQ['memberid'];
	}
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['mobile']){
		$params2['mobile like']='%'.trim($_RQ['mobile']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['mobile']=$_RQ['mobile'];
	}
	//创建时间
	if($_RQ['timenum']){
		$time_range=cfc('tools')->base64_decode($_RQ['timenum'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['timenum']=$time_range;
		$params['timenum between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$total='';
	$list=pdo_getslice('jy_yxw_fenfee_log',$params,array($pindex,$psize),$total,$fields,'','id asc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			if(!$item['status'] && $item['tofee']>0){
				$item['fee']=$item['tofee'];
			}
			if($_RQ['status']==6){
				$item['isday']=1;
			}else{
				$item['isday']=0;
			}
			if($item['status']==1){
				$isfeelog=pdo_get('jy_yxw_feelog',array('fenfeeid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
				if(!$isfeelog['id']){
					$this->model('feelog')->upfeelog($item['id'],'',2);
				}
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'storeid','title'=>'所属门店','type'=>'select2','options'=>'stores'),
			array('name'=>'sn','title'=>'期号','type'=>'string'),
			array('name'=>'fee','title'=>'应缴费用','type'=>'string'),
			array('name'=>'isfee','title'=>'实缴费用','type'=>'string'),
			array('name'=>'time','title'=>'应缴时间','type'=>'string'),
			array('name'=>'payday','title'=>'实缴时间','type'=>'string'),
			array('type'=>'string','title'=>'收款账户','name'=>'zhanghu'),
			array('type'=>'radio2','title'=>'状态','name'=>'status','options'=>'status'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_yxw/role14.fenfee_log/check/','title'=>'处理缴费','show'=>array('isday'=>1)),
			array('type'=>'href','action'=>'jy_yxw/role14.fenfee_log/check/','title'=>'提前处理缴费','show'=>array('isday'=>0,'status'=>0)),
		)),
		'search'=>array(
			array('name'=>'title','width'=>10,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>10,'title'=>'电话','type'=>'string'),
			array('name'=>'timenum','width'=>30,'title'=>'应缴时间','type'=>'time_range'),
		)
	);
	if($_RQ['status']==1){
		$htmls['list']['list'][]=array('name'=>'up_time','title'=>'实缴时间','type'=>'time');
		$htmls['list']['list'][]=array('name'=>'up_workerid','title'=>'操作人','type'=>'select','options'=>'workers');
	}
	if($_SESSION['role_id']==14 || $_SESSION['role_id']==15 || $_SESSION['role_id']==17){
		$htmls['search'][]=array('name'=>'storeid','width'=>15,'title'=>'所属门店','type'=>'select','options'=>'stores');
	}elseif($_SESSION['storeids']){
		$htmls['search'][]=array('name'=>'storeid','width'=>10,'title'=>'所属门店','type'=>'select','options'=>'stores');
	}
	$return['status']=array('待缴费','已缴费','缴费异常');
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['id']=$_SESSION['storeids'];
	}
	$return['stores']=$this->getall('store',$params,array('id','title'),'id');
	$return['workers']=$this->getall('worker',array('role'=>14,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	$return['pay_types']=$this->pay_types;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if(!$post['isfee'] || $post['isfee']<=0){
			exi('请先输入【实缴费用】!','error');
		}
		$id=$post['id'];
		$data=array(
			'isfee'=>$post['isfee'],
			'remark'=>trim($post['remark']),
			'zhanghu'=>trim($post['zhanghu']),
			'status'=>intval($post['status']),
			'payday'=>$post['payday'],
			'paydaytime'=>strtotime($post['payday']),
		);
		$data['uniacid']=$_SESSION['uniacid'];
		$data['up_time']=time();
		$data['up_workerid']=$_SESSION['workerid'];
		$this->update('fenfee_log',$data,array('id'=>$id));
		if($post['isdai']){
			$this->model('feelog')->upfeelog($id,'',7);
		}else{
			$this->model('feelog')->upfeelog($id,'',2);
		}
		exi('操作成功！','','/role14.fenfee_log//status=6');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_fenfee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['title']=pdo_getcolumn('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['memberid']),'title');
		$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
	}else{
		exi('请先选择记录','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'应缴收款',
	);
	$htmls['edit']=array(
		array('type'=>'copy','title'=>'售后姓名','name'=>'title'),
		array('type'=>'copy','title'=>'成交售后群','name'=>'classtitle','show'=>array('classid >'=>0)),
		array('name'=>'sn','title'=>'期号','type'=>'copy'),
		array('name'=>'time','title'=>'应缴时间','type'=>'copy'),
		array('type'=>'copy','title'=>'应缴费用','name'=>'fee'),
		array('type'=>'unitstring','unit'=>'元','title'=>'实缴费用','name'=>'isfee'),
		array('type'=>'time','title'=>'实缴日期','name'=>'payday','time_type'=>'day'),
		array('type'=>'string','title'=>'收款账户','name'=>'zhanghu'),
		array('type'=>'radio','title'=>'审批状态','name'=>'status','options'=>'status'),
		array('type'=>'text','title'=>'审批备注','name'=>'remark'),
	);
	$return['status']=array('待缴费','已缴费','缴费异常');
	$return['pay_types']=$this->pay_types;
	$return['daipay_types']=$this->daipay_types;
	$return['htmls']=$htmls;
	exi($return);
}
